﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections;

namespace LUStationery.DAO
{
    public class DepartmentDAO
    {

        SqlConnection cn;
        SqlCommand cmd;


        public DepartmentDAO()
        {
            cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
           
        }
        public IDataReader getDepartment()
        {
            cmd = new SqlCommand("Select * from Department", cn);
            cn.Open();
            IDataReader idr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            return idr;
            

        }


        public IDataReader getDepartmentByDeptCode(string deptCode)
        {
            
            cmd = new SqlCommand();
            cmd.Connection = cn;
            cmd.CommandText = "select * from department where department_code=@deptCode";
            cmd.Parameters.Add("@deptCode", SqlDbType.VarChar).Value = deptCode;
            cn.Open();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }


        public int updateDeptInfo(string DeptCode, string Representative, string CollectionPoint)
        {
            cmd = new SqlCommand();
            cmd.Connection = cn;
            cmd.CommandText = "update department set collection_point=@collection_point,representative=@representative where department_code=@department_code";
            cmd.Parameters.Add("@department_code", SqlDbType.VarChar).Value = DeptCode;
            cmd.Parameters.Add("@collection_point", SqlDbType.VarChar).Value = CollectionPoint;
            cmd.Parameters.Add("@representative", SqlDbType.VarChar).Value = Representative;
            cn.Open();
            int flag=cmd.ExecuteNonQuery();
            return flag;
        }

    }
}